package com.xb.p34_mvcdemo;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;


public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    EditText et_x,et_y;
    Button btn_ok;
    MyView myView;

    int x1=150,y1=150;//初始的位置信息

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        et_x=findViewById(R.id.et_x);
        et_y=findViewById(R.id.et_y);
        btn_ok=findViewById(R.id.btn_ok);
        myView=findViewById(R.id.my_view);
        myView.setXY(x1,y1);

        btn_ok.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        x1=Integer.parseInt(et_x.getText().toString());
        y1=Integer.parseInt(et_y.getText().toString());

        myView.setXY(x1,y1);
        myView.invalidate();//刷新一下
    }
}